﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace StrategyPattern
{
    interface IDisplay
    {
        void Display();
    }

    interface ISwim
    {
        void Swim();
    }

    interface IFly
    {
        void Fly();
    }



    class DisplayWhile : IDisplay
    {
        void IDisplay.Display()
        {
            Console.WriteLine("白兔子");
        }
    }

    class DisplayBlack : IDisplay
    {
        public void Display()
        {
            Console.WriteLine("黑兔子");
        }
    }


    class SwimNormal : ISwim
    {
        public void Swim()
        {
            Console.WriteLine("会游泳的");
        }
    }

    class SwimNo : ISwim
    {
        public void Swim()
        {
            Console.WriteLine("不会游泳的");
        }
    }

    class FlyNormal : IFly
    {
        public void Fly()
        {
            Console.WriteLine("不会游泳的");
        }
    }

    class FlyNo : IFly
    {
        public void Fly()
        {
            Console.WriteLine("不会游泳的");
        }
    }

    class Duck
    {
        IDisplay _display;
        IFly _fly;
        ISwim _swim;

        public Duck(IDisplay display, ISwim swim, IFly fly)
        {
            _display = display;
            _fly = fly;
            _swim = swim;
        }

        public void Display()
        {
            _display.Display();
        }
        public void Swim()
        {
            _swim.Swim();
        }
        public void Fly()
        {
            _fly.Fly();
        }
    }


    class Program
    {

        static void Main(string[] args)
        {

        }

        #region
        static int a = 0;
        static int b = 0;
        private static object o = new object();

        private static void Test()
        {

            Thread t1 = new Thread(A);
            t1.Start();
            Thread t2 = new Thread(B);
            t2.Start();
            Thread t3 = new Thread(C);
            t3.Start();
            Console.ReadLine();
        }

        private static void A()
        {
            lock (o)
            {
                a = a + 2;
                Console.WriteLine("我是A方法，a =" + a);
                Thread.Sleep(5000);//暂停5秒
                b = b + 2;
                Console.WriteLine("我是A方法，b =" + b);
            }
            Console.WriteLine("A");
        }
        private static void B()
        {
            lock (o)
            {
                b++;
                Console.WriteLine("我是B方法，b =" + b);
                Thread.Sleep(1000); //暂停1秒
                a++;
                Console.WriteLine("我是B方法，a =" + a);
            }
            Console.WriteLine("B");
        }
        private static void C()
        {
            Console.WriteLine("我是C方法，随机出现");
        }

        #endregion
    }
}
